package com.itheima.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class MyAspect1 {
    @Pointcut("execution(* com.itheima.service.impl.*.*(..))")
    public void pt(){}
    //前置通知
    @Before("@annotation(com.itheima.anno.LogOperation)")
    public void before(JoinPoint joinPoint){
        //获取目标对象
        Object target = joinPoint.getTarget();
        log.info("target:{}",target);
        //获取目标方法的参数
        Object[] args = joinPoint.getArgs();
        log.info("args:{}",args);
        //获取目标方法名称
        String methodName = joinPoint.getSignature().getName();
        log.info("methodName:{}",methodName);

        log.info("before...");
    }
    //环绕通知
    @Around("pt()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        log.info("around before...");
        Object retVal = pjp.proceed();
        log.info("around after...");
        return retVal;
    }
    //后置通知
    @Before("pt()")
    public void after(){
        log.info("after...");
    }
    //返回后通知
    @AfterReturning("pt()")
    public void afterReturning(){
        log.info("afterReturning...");
    }
    //异常后通知
    @AfterThrowing("pt()")
    public void afterThrowing(){
        log.info("afterThrowing...");
    }
}
